-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style(import): consistently use relative imports #1330
Conversation
b91929f
to
f39c7fb
Compare
f39c7fb
to
c6feffc
Compare
@@ -3,6 +3,8 @@ | |||
import datetime | |||
import textwrap | |||
from enum import Enum | |||
|
|||
# keep below as absolute imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find. This was the only one I could think of that shouldn't be relative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was my finding too. Scripts need to have absolute imports. It is run in modflow6's autotest/update_flopy.py
* doc: initialize development branch * doc: update mf6 output tutorial (#1175) * binder: update binder yml (#1178) * fix(grid, plotting): bugfixes for all grid instances and plotting code (#1174) * grid fix iverts and verts; expose laycbd for use in utilities * plotting add RuntimeError exception to matplotlib imports to fix Condor containerization issues with flopy * fix(loading mflist from file) (#1179) @aleaf @jtwhite79 has addressed this issue. See modified test (`t004_test_utilarray.py`) for an example of using external files for list data. Reopen if this does not solve your issue. Closes #1073 * refactor: clean-up python 2 'next' and redundant '__future__' imports (#1181) * fix(raster): rework raster threads to work on osx (#1180) * update(MF6Output): access list file object via <model>.output.list() (#1173) * update(MF6Output): updates to access the list file using <model>.output.list() * revert unintended changes due to version conflict in mfmodel.py * fix(pakbase): specify dtype=bool for 0-d active array used for USG (#1188) * fix(modflow/mfriv) unstructured mfusg RIV package load check fix (#1184) flopy fails on checking mfusg unstructured RIV packages * add unstructured clause / disu reference to modflow/mfriv * modify autotest/t016.py test_usg_rch_evt_models01 to include a riv file and check() call * feat(lak6): support none lake bedleak values (#1189) Also modified gridintersect.plot_linestring to accept a matplotlib colormap string. * fix(plot/plot_bc) plot_bc fails with unstructured models (#1185) * fix(plot/plot_bc) plot_bc fails with unstructured models In plot/map.py, with unstructred models, numpy throws "too many indices for array" error when indexing plotarray with a tuple of boundary condition node numbers. * Revert plotarray BC indices to stress_period_data list[kper]["node"] as-is for unstructured models. * add plot_bc tests to t506_test.py for unstructured mf6 and mfusg models * update(python): set python 3.7 as minimum supported version (#1190) Also set minimum NumPy version to >= 1.15. Add python 3.9 to GitHub action workflows and remove python 3.6. Closes #1176 Closes #1177 * refactor(numpy): remove support for numpy<1.15 (#1191) * Fix(MF6Output): fix add new obs package issue (#1193) * update MF6Output gwt list() method to use MfListBudget * Added test to t504_test.py for adding new observations * refactor(plot): remove deprecated plot methods (#1192) Remove deprecated plot_discharge and plot_specific_discharge * fix(pakbase) unstructured storage check (#1187) (#1194) in pakbase/_check_storage.py, np.asarray() still throws an error when using a jagged list for unstructured models #1187 (comment) * change to np.concatenate jagged list to a flat array * skip storage check if no convertible layers Closes #1187 * refactor(thickness): remove deprecated dis and disu thickness property (#1195) deprecated mfdis and mfdisu thickness property * fix(Grid.saturated_thick): update saturated_thick to filter confining bed layers (#1197) * added Grid.remove_confining_beds() * added test_ncb_thick() to t076_modelgrid_thick.py * refactor(SR): remove deprecated SpatialReference class (#1200) * refactor(pakbase): generate heading from base class (#1196) * refactor: replace OrderedDict with dict (#1201) * refactor(reference): remove deprecated crs and epsgRef classes (#1202) Update t007 so that it does not fail if there is no internet connection on GitHub Actions VMs. * refactor(deprecated): remove additional deprecated classes and functions (#1204) * readme: update README.md badges and script to update badge branch (#1206) * updates(zonbud, output_util, mfwel, OptionBlock): updates and bug fixes (#1209) * autotest updates for deprecations and updates * updates(zonbud, output_util, mfwel, OptionBlock): updates * remove deprecated code from zonbud.py * remove deprecated code form mfwel.py * fix MF6Output.list(), update to use Mf6ListBudget * fix Package.load() for mfnwt_options, well options not passed to well file when option block detected * Remove references to deprecated code from notebooks * refactor(zonebud): reapply OrderedDict to dict changes from PR #1201 (#1210) * fix(numpy): handle deprecation warnings from numpy 1.21 (#1211) * docs(readme): update mf6 quickstart to use plot_vector() (#1215) * style: use f-strings to format str (#1212) * fix(rename and comments): package rename code and comment propagation (#1226) * fix(rename and comments): fixed package rename code (#1133). fixed problem with comments not propagating properly when data switched between internal and external (#1183). * fix(reformat) * fix(f strings) * fix(export test case fix): call write after export so that netcdf file closes properly before object is destroyed * fix(shapefile_utils) unstructured shapefile export (#1220) (#1222) * Fix errors encountered when exporting to shapefile from unstructured models. See #1220 * add unstructured clauses to export/shapefile_utils.py for static arrays (e.g. DISU, LPF, BAS6). More work needed for boundary conditions (MFList and transientlist data types - eg RIV/RCH/EVT packages) * add test to t506.py to export mfusg aunstructured model shapefiles * close #1220 * refactor: use print() instead of sys.stdout.write() (#1223) * refactor(exceptions): reduce redundancy, simplify message generation (#1218) Remove PlotException, replace with KeyError and ImportError * refactor(exceptions): reclassify IOError as OSError or other type (#1227) * [modflowpy/flopy] update(ModflowHob): Improve HOB file performance #1158 (#1224) (#1225) Co-authored-by: Hua Zhang <hzhang4@gmail.com> * docs: black formatting of mfhob * fix(numpy elementwise comparison): Fixed numpy FutureWarning. No elementwise compare is needed if user passes in a numpy recarray, this is only necessary for dictionaries. (#1235) * feat(mf6): allow multi-package for stress package concentrations (SPC) (#1242) * Support new mf6 transport utility for specifying concentrations for boundary conditions * fix(writing tas): fixed writing non-constant tas (#1244) (#1245) * Close #1244 * Update(Vtk): updates to Vtk class for MF6, HFB, and MODPATH (#1249) * update(flopy3_vtk_export.ipynb): updates for new VTK class and routines * update(vtk.py): rewrite of Vtk() class and functions for Vertex and Unstructured Grids, MODPATH * New dependency added (python vtk package: pip install vtk) * Added support for HFB package * Added support for MODPATH pathline and timeseries output * Updated the support for head exports and cell budget files * minor update to deprecated methods * updates to test_vtk_vector() and test_vtk_pathline() * fix(voronoi): VoronoiGrid class upgraded to better support irregular domains (#1253) * revised VoronoiGrid class * added more tests * changes are not backward compatible as VoronoiGrid now requires flopy Triangle object as input instead of points * Close #1095 * fix(MFPackage): fix mfsim.nam relative paths (#1252) * update MFPackage for t505_test.py * ci(voronoi): test script was not running (#1255) * feat(CellBudget): add support for full3D keyword (#1254) * refactor(Package): simplify __init__ in subclasses, remove "extra" (#1238) * Think mg extent is x0,x1,y0,y1? (#1243) * Think mg extent is x0,x1,y0,y1? * Update t007_test.py for ASCII grid extent bugfix Co-authored-by: Joshua Larsen <jlarsen@usgs.gov> * refactor(netcdf): sync data, revise logger and exceptions (#1230) * Fix(_mg_resync): Added checks to reset the modelgrid resync (#1258) * update to allow model to resync modelgrid when discretization or bas package is modified * added test_mf6_modelgrid_update to t007_test.py * fix(MFFileMgmt.string_to_file_path): updated to support UNC paths (#1256) * added test_mf6_string_to_file_path to t501_test.py * Close #1237 * feat(get_ts): added support to get_ts for HeadUFile (#1260) * Refactor(mfusg), Feat(mfusgcln, mfusggnc) (#1261) * modflowusg * refactor(modflowusg) * Refactor(mfusg), Feat(mfusgcln, mfusggnc) * refactor(t420_test.py) for mfusg restructure * rename(modflowusg-->mfusg) rename all modules, classes etc for simplicity * rename(t420_test.py-->t080_test.py) Co-authored-by: swfwmd <hua.zhang@swfwmd.state.fl.us> * refactor(imports): add function to import optional packages (#1262) matplotlib is now a FloPy requirement. Closes #1257 * Fix(ModflowFhb): update datasets 4, 5, 6, 7, 8 loading routine for multiline records (#1264) * fix(keystring records): fixed problem with keystring records containing multiple keywords (#1266) * fixes(1247): Make flopy buildable with pyinstaller (#1248) Use __init_subclass__ to register packages, removing dependency on dfn files when installed. Rename longnames.json and unitsformat.json to .py so they are automatically included. * refactor(setup): prefer setup.cfg for package metadata, and other changes (#1267) * Assign one author and one maintainer, which is expected by PyPI * Expand a few classifiers, add keywords and project URLs * Use python_requires, auto-find packages, and set zip_safe=False * Add pyproject.toml with black configuration, with default "-l 79" * Remove pypandoc dependency, specify 'text/markdown' content type * Change default sdist format to zip * ci: add workflow to test flopy-based MODFLOW 6 tests (#1272) * @spaulins-usgs fix(model/IMS registration and model relative path) (#1273) * fix(model/IMS registration and model relative path): register_ims_package now unregisters models from other IMS packages before registering the model to the new IMS package, enforcing the rule that a model can not be registered to more than one IMS package. Model relative paths fixed in cases where model relative path set before package creation. * fix(tests): added test simulation with four models to increase test coverage of ims file registration and exchanges * ci: convert from nosetest to pytest (#1274) * ci: convert addition autotests to use flopyTest testing framework (#1276) * ci: convert addition autotests to use flopyTest testing framework (#1278) * Updates(MF6Output): Added budgetcsv method to .output attribute (#1275) * Update dfn files to most recent modflow6 dfns * Ran createpackages.py to apply updates for budgetcsv output type * Added budgetcsv method .output * Fix ModflowUzf1.load(), use built in multiline reader method instead of readline() (crashed on comment line after options block). * ModflowAg add accel option to option block * ci: refactor FlopyTestSetup testing class (#1283) * fix(io): read comma separated list (#1285) modified: flopy/utils/flopy_io.py Close #1285 * update(CellBudgetFile, MF6Output): update to pass modelgrid to CellBudgetFile and reshape arrays using full3D option (#1282) * fix(mfusg/str) (#1296) * cater for unstructured mfusg models in modflowstr * add mfusg str load/write test to t016_test * close #1295 * black * ci: switch from conda to standard python and pip (#1293) * update(Raster): added min and max resampling for hydrologic resampling and streamflow representation (#1294) * added trap for nodata within polygons * added test_raster_sampling_methods to t065_test_gridintersect.py * fix(path): fix subdirectory path issues (#1298) * Checking for model_relative_path already existing in external file filename, which will be the case when reading in a model. Will only append model_relative_path where not already present in file name. Should improve support for models using external file storage and simulations with models in sub directories. * Added test to t501 to catch subdir issue * Close #1289 * Possibly related to #1115 and #1126 * fix(geospatial_utils.py): added pyshp and shapely imports check to geospatial_utils.py (#1305) * reorganized code order to enforce import checks * fix(autotests): added pytest.ini to declare test naming convention (#1307) * fix(plot_pathline): sort projected pathline points by travel time instead of cell order #1302 * Linting * fix(autotests): added pytest.ini to declare test naming convention * fixed t069_test_vtkexportmodel.py * updated voronoi tests in t075_test_ugrid.py * fixed ulstrd open/close read method for scale factors * revert changes made to voronoi tests * revert all changes to t075_test_ugrid.py * fix(plot_pathline): sort projected pathline points by travel time instead of cell order (#1304) * feat(Gridintersect): add shapetype kwarg (#1301) * refactor(make-release): Software citation developed from version.py * release: update mf6 v6.1.1 dfn and flopy mf6 classes (#1) * docs(misc): clean up docstrings * refactor(GridIntersect): fix error message for unsupported methods * bug(GridIntersect): fix #10 ensure one entry per grid cell in polygon intersection result add test for this case * bug(gridintersect): fixes #917 bug in structured mode where linestrings were not handled correctly if they pass in and out of grid cell * fix(GridIntersect): #1035 - fix vertices when intersecting linestring with offset grids * feat(GridIntersect): add shapetype kwarg allow intersection shape to be passed as list of vertices (modify test to test this) specify keyword arguments explicitly in intersect calls formatting Co-authored-by: jdhughes-usgs <jdhughes@usgs.gov> Co-authored-by: Christian Langevin <langevin@usgs.gov> Closes #727 * fix(array): getting array data (#1028) (#1290) * fix(array): Getting array data (<data object>.array) fixed so that empty stress periods repeat data from the last previous stress period with data. If there is no previous stress period with data, None is used for MFDataList arrays and an array of zeros is used for MFDataArray arrays. * fix(array): added test cases for getting array data (<Data Object>.array) * fix(array and getdata): array and getdata now return appropriate values for "nodata" and "repeating last stress period data" cases * fix(array and getdata): added tests for array and getdata for different types of empty stress periods * fix(array output): minor fix for how arrays output data * fix(test): fixed convergence issues with new test case * linting with updated version of black (#1315) * fix(UnstructuredGrid): load vertices for unstructured grids (#1312) * Loading an mf6 DISU model with variable voronoi grid results in extraneous iverts entries of None (Iverts appears to be a consistent (not jagged) shape). This results in a vertexdict indexing error in UnstructuredGrid._build_grid_geometry_info when using plot() methods. * Filter out None entries from iverts in UnstructuredGrid._build_grid_geometry_info * update(VertexGrid): added filter for None types on cell2d * fix(paths): Path code made more robust so that non-standard model folder structures are supported (#1311) (#1316) * fix(paths): Path code made more robust so that non-standard model folder structures are supported. There are three basic path times, the path to the simulation, model relative paths to particular models in the simulation, and package/data relative paths to package or data files in a model or simulation. Model relative paths are relative to the simulation path. Package/data relative paths are relative to the simulation path for packages/data not attached to a model and relative to model relative path for packages/data attached to a model. (#1311) * test(paths): added more comprehensive testing of paths Co-authored-by: Scott Paulinski <spaulinski@usgs.gov> * fix(filenames): fixed how spaces in filenames are handled (#1236) (#1318) * fix(filenames): fixed how spaces in filenames are handled. filenames with spaces in them now are read correctly from the package files and are written to the package file in quotes (#1236) * fix(filenames): test cases now include filenames with spaces in them * ci: update t058 to fix issue on macos with python 3.9 (#1320) update remaining tests to use new testing functionality to avoid possible race conditions with parallel pytest * update(Gridgen): added keyword arguments for smoothing_level_vertical and smoothing_level_horizontal (#1322) Close #1317 * fix(voronoi): clean up voronoi examples and add error check (#1323) * Close #1299 * Voronoi issues in example were caused by closed polygons being passed to triangle * Revised examples to meet requirements * Add check for duplicate vertices in triangular mesh * Updated t075 to check for invalid cells * Changed several filtering loops in grid methods to use standard list comprehension * feat(multiple package instances): FloPy support for multiple instances of the same package stored in dfn files (#1239) (#1321) * ci: add separate windows workflow that uses miniconda (#1324) * feat(inspect cells): new feature that returns model data associated with specified model cells (#1140) (#1325) * feat(inspect cells): new feature that returns model data associated with specified model cells (#1140) * feat(inspect cells): added tests for new feature (#1140) * feat(inspect cells) * feat(inspect cells): dependent variable and budget inspection * feat(inspect cells): tests * feat(inspect cells): doc update * feat(inspect_cells) * feat(inspect_cells) * ci(diagnose): create failedTests artifact (#1327) * update(Grid.intersect): added optional z-coordinate to intersect() method (#1326) * update(Grid.intersect): added optional z-coordinate to intersect() method * implemented intersect method for UnstructuredGrid * update(Grid): Added interface change warnings to intersect method * style(import): consistently use relative imports (#1330) * Convert line endings to UNIX; remove BOM * Use relative imports * fix(Raster): resample_to_grid failure no data masking failure with int dtype (#1328) * update(test_raster_sampling_methods): update for mean resampling * refactor(distutils): Version classes are deprecated, use internal class (#1331) * fix(postprocessing): get_structured_faceflows fix to support 3d models (#1333) * function was fixed to support multi-layer models * test added to ensure face flow calculations work * fix(cellid): Fixes some issues with flopy properly identifying cell ids (#1335) (#1336) * fix(ModflowUtllaktab): utl-lak-tab.dfn is redundant to utl-laktab.dfn (#1339) * style(imports): use isort tool, remove unused imports (#1341) * ci: Add isort to linting step (#1343) Update flopy using latest version of black. Add autotest\pull_request_prepare.py to help contributors to run isort and black prior to a pull request. Clean-up unused examples/Testing directory. Modified t064_test_performance.py to guard against failures on macOS. * ci: restrict use of pyshp=2.2.0 until ci failure issue resolved (#1345) * update(MFBlockHeader): fix for extremely slow loading of package OBS files when many blocks exist in OBS file. (#1351) update header_exists: when None is provided for key, do not check against block header names (significantly speeds OBS loading). * update(read_binary_data_from_file): update for binary layer files with multiple layers (#1352) Previously code read the entire file without stripping headers after first layer. Enforce read_multi_layer=True if data_size != ncpl * update to support both "layered" binary files and flat binary files * update(read_binary_data_from_file): check for ncpl as numpy array * added test_binary_read to t505_test.py * update(geometry.py): added __reversed__ to geometry objects (#1347) * update(t074_test_geospatial_util.py): update tests for pyshp 2.2.0 * fix typo in AG package * update Raster for slightly faster grid resampling * update(geometry.py): added __reversed__ to geometery object as patch for pyshp 2.2.0 vs 2.1.0 differences * updated t074_test_geospatial_util.py * linted repository * isort mfag.py * update black and perform linting * update(requirements): merge upstream pyshp requirements with fork * update(requirements): update pyshp requirements to pyshp >= 2.0.0 * update(requirements.txt): resolve conflict * update(contouring routines): updates for contour_array and export_contourf routines (#1353) * added filled kwarg to contour_array for filled contours * update PlotCrossSection.contour_array() to mask out edge triangles outside of cross-section boundaries * update export_contourf, provide support for multipolygon contours and update support for holes * update export_contourf, remove shapely dependency. Replaced with flopy geometry objects * update t007_test.py, test_export_contourf() * fix(tab files): fixed searching for tab file packages (#1337) (#1344) Added lake tab file back in to t504 tests (#1337). Modified lak test to test tab files in different folders. Changed lakeex1b.lak test file path to contain mac-style forward slash path Co-authored-by: Scott Paulinski <spaulinski@usgs.gov> closes #1337 * refactor(flake8): F821 for 'undefined name' errors (#1350) * feat(gwtgwt-mvt): add support for gwt-gwt with mover transport (#1356) * feat(mvt): add simulation-level support for mover transport (#1357) * feat(mvt): add simulation-level support for mover transport * run black * fix(exchange obs): fixed building of obs package for exchange packages (through MFSimulation) (#1363) * fix(exchange obs): fixed building of obs package through MFSimulation class * fix(exchange obs): updated comments * fix(exchange obs): test coverage for exchange obs * release: version 3.3.5 Co-authored-by: Joshua Larsen <jlarsen@usgs.gov> Co-authored-by: J Dub <jtwhite1000@gmail.com> Co-authored-by: Mike Taves <mwtoews@gmail.com> Co-authored-by: Chris Nicol <37314969+cnicol-gwlogic@users.noreply.github.com> Co-authored-by: langevin-usgs <langevin@usgs.gov> Co-authored-by: spaulins-usgs <spaulinski@usgs.gov> Co-authored-by: swfwmd <43884652+swfwmd@users.noreply.github.com> Co-authored-by: Hua Zhang <hzhang4@gmail.com> Co-authored-by: Brioch Hemmings <briochh@gmail.com> Co-authored-by: Ross Kushnereit <30669053+rosskush@users.noreply.github.com> Co-authored-by: swfwmd <hua.zhang@swfwmd.state.fl.us> Co-authored-by: Tim Mitchell <tim.mitchell@seequent.com> Co-authored-by: Michael Ou <ougengxin@gmail.com> Co-authored-by: Davíd Brakenhoff <d.brakenhoff@artesia-water.nl> Co-authored-by: scottrp <45947939+scottrp@users.noreply.github.com>
Reading this comment (the link doesn't seem to work for a resolved conversation) it seems that relative imports are the preferred convention in this project. However, they are not consistently used everywhere. This PR makes them consistent.
The first commit converts two DOS files to UNIX line endings, and removes an unnecessary BOM in another file. This is done to distinguish the edits done by absolufy-imports.
And the second commit was automated using:
If some of the absolute imports are actually preferred (e.g. imports within functions), then this PR can be reduced to fix just the imports at the top of the files, which is the primary inconsistency.
In further developments, I've been looking at using isort to sort/organize imports. However, this would require further investigations to resolve circular imports, which can take a while to assess.